package be.sc.classicnetwork.aspect;

import java.util.Map;

import javax.servlet.ServletContext;

import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.web.context.ServletContextAware;

import be.sc.classicnetwork.service.ServiceLocator;

/**
 * RefreshCacheAspect.
 */
@Aspect
public class RefreshCacheAspect implements ServletContextAware {

	private ServiceLocator serviceLocator;

	private ServletContext servletContext;

	/**
	 * flushCache.
	 */
	@SuppressWarnings("unchecked")
	@After("@annotation(be.sc.classicnetwork.annotation.RefreshCache)")
	public void refreshCache() {
		Map cache = this.serviceLocator.getCarService().getCache();
		servletContext.setAttribute("cache", cache);
	}

	public ServiceLocator getServiceLocator() {
		return serviceLocator;
	}

	public void setServiceLocator(ServiceLocator serviceLocator) {
		this.serviceLocator = serviceLocator;
	}

	public void setServletContext(ServletContext servletContext) {
		this.servletContext = servletContext;
	}
}
